﻿using Basic.WxRemoteModel.WxPlatform.Model;
using WeDonekRpc.Helper;

namespace Basic.WxGatewayModular.Model
{
    public class WxPlatform
    {
        private readonly string _DecryptKey;
        private readonly string _MsgToken;
        private readonly int _OverTime;
        public WxPlatform (WxPlatformDto obj)
        {
            this._OverTime = HeartbeatTimeHelper.HeartbeatTime + 600;
            this.AppId = obj.AppId;
            this._MsgToken = obj.MsgToken;
            this._DecryptKey = obj.DecryptKey;
        }

        public string AppId { get; }

        public int OverTime => this._OverTime;

        public string Decrypt (string encrypt)
        {
            return Cryptography.AES_decrypt(encrypt, this._DecryptKey);
        }
        public string GetMsgSign (string nonce, string timestamp)
        {
            string[] str = new string[3]
            {
                this._MsgToken,
                nonce,
                timestamp
            };
            Array.Sort(str);
            return Tools.Sha1(str.Join());
        }
    }
}
